<template>
  <ContentWrap>
    <el-form :model="queryParams" label-width="100px" class="flex items-center">
      <el-form-item label="设备ID">
        <el-input
          v-model="queryParams.deviceId"
          placeholder="请输入设备ID"
          clearable
          class="!w-200px"
        />
      </el-form-item>
      <!-- 按钮 -->
      <el-form-item>
        <el-button type="primary" @click="getDeviceLogPage">查询</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>
  <ContentWrap>
    <el-table
      :data="tableData"
      :loading="loading"
      style="width: 100%"
      :stripe="true"
      :show-overflow-tooltip="true"
    >
      <el-table-column label="操作时间" prop="createTime" align="center">
        <template #default="scope">
          <span>{{ formatDate(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" prop="type" align="center" />
      <el-table-column label="操作" prop="content" align="center" />
      <el-table-column label="状态" prop="typeStr" align="center" />
      <el-table-column label="设备" prop="deviceId" align="center" />
      <el-table-column label="设备名称" prop="deviceName" align="center" />
      <el-table-column label="备注" prop="remark" align="center" />
    </el-table>
    <Pagination
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      :total="total"
      @change="getDeviceLogPage"
    />
  </ContentWrap>
</template>
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { SofaBasicApi } from '@/api/application/sofa'
import { formatDate } from '@/utils/formatTime'
const tableData = ref([])
const total = ref(0)
const queryParams = ref({
  pageNo: 1,
  pageSize: 10,
  deviceId: ''
})
const loading = ref(false)
const getDeviceLogPage = async () => {
  loading.value = true
  try {
    const res = await SofaBasicApi.getDeviceLogPage(queryParams.value)
    tableData.value = res.list
    total.value = res.total || 0
  } catch (error) {
    console.log(error)
  } finally {
    loading.value = false
  }
}
onMounted(() => {
  getDeviceLogPage()
})
</script>
<style lang="scss" scoped></style>
